#include <iostream>
#include <mutex>
#include <atomic>
#include <unistd.h>

using namespace std;

class singleton
{
public:
	static singleton* getInstance() {
		if (ptr == nullptr) {
			_mtx.lock();
			if (ptr == nullptr) {
				ptr = new singleton();
			}
			_mtx.unlock();
		} 
		return ptr;
	}

	class cb
	{
	public:
		~cb() {
			if (ptr) {
				std::cout << "析构" << std::endl;
				delete ptr;
				ptr = nullptr;
			}
		}
	};

	static cb b;
private:
	singleton();
	singleton(const singleton&) = delete;
	singleton& operator=(const singleton&) = delete;

	static std::mutex _mtx;
	static singleton *ptr;
};

std::mutex singleton::_mtx;
singleton* singleton::ptr = nullptr;
singleton::cb b;



int64_t getCurrentTimeMicroseconds() {
	return std::chrono::duration_cast<std::chrono::microseconds>(
		std::chrono::steady_clock::now().time_since_epoch()).count();
}

int main()
{
	std::cout << getCurrentTimeMicroseconds() << '\n';

    return 0;
}